<!-- 货代企业管理 - 综合表单页面 -->
<template>
  <div class="page-container">
    <ex_super_table_page v-bind="option" ref="superTablePage">
    </ex_super_table_page>


    <el-dialog :title="dialogTitle" :visible.sync="dialogFormVisible" customClass="dialog_default">
      <el-form ref="formEl" :model="formValue" :rules="rules" label-width="120px"
        style="padding: 0px;">
        <ex_header_spiler :title="$tt('label_base_info')"></ex_header_spiler>
        <el-row>
          <el-col :span="24" :md="12">
            <el-form-item :label="$tt('label_company_name')" prop="companyName">
              <el-input v-model="formValue.companyName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24" :md="12">
            <el-form-item :label="$tt('label_company_code')" prop="companyCode">
              <el-input v-model="formValue.companyCode"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24" :md="12">
            <el-form-item :label="$tt('label_company_short')">
              <el-input v-model="formValue.companyShortName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24" :md="12">
            <el-form-item :label="$tt('label_unified_credit_code')">
              <el-input v-model="formValue.companyCreditCode"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24" :md="12">
            <el-form-item :label="$tt('label_legal_person_name')">
              <el-input v-model="formValue.legalPerson"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24" :md="12">
            <el-form-item :label="$tt('label_corporate_ID_number')">
              <el-input v-model="formValue.legalIdNo"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24" :md="12">
            <el-form-item :label="$tt('label_company_landline')">
              <el-input v-model="formValue.companyTel"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24" :md="12">
            <el-form-item :label="$tt('label_mailbox')">
              <el-input v-model="formValue.email"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item :label="$tt('label_register_address')">
              <ex-address v-model="formValue.registAddress" :clearable="true"></ex-address>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item :label="$tt('label_mail_address')">
              <ex-address v-model="formValue.mailAddress" clearable></ex-address>
            </el-form-item>
          </el-col>
        </el-row>

        <ex_header_spiler :title="$tt('label_contact_info')"></ex_header_spiler>
        <el-row>
          <el-col  :span="24" :md="12">
            <el-form-item :label="$tt('label_contact_name')">
              <el-input v-model="formValue.contactName"></el-input>
            </el-form-item>
          </el-col>
          <el-col  :span="24" :md="12">
            <el-form-item :label="$tt('label_contact_idcard_number')">
              <el-input v-model="formValue.contactIdNo"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24" :md="12">
            <el-form-item :label="$tt('label_contact_phone')">
              <el-input v-model="formValue.contactPhone"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24" :md="12">
            <el-form-item :label="$tt('label_contact_job')">
              <el-input v-model="formValue.contactPosition"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item :label="$tt('label_tms_is_test_company')">
              <el-radio-group v-model="formValue.isTest">
                <el-radio label="Y">{{ $enumShow('Y', 'YesOrNoEnum') }}</el-radio>
                <el-radio label="N">{{ $enumShow('N', 'YesOrNoEnum') }}</el-radio>
              </el-radio-group>

            </el-form-item>
          </el-col>

        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">{{ $tt('label_cancel') }}</el-button>
        <el-button type="primary" @click="submitForm">{{ $tt('label_confirm') }}</el-button>
      </div>
    </el-dialog>


  </div>
</template>
<script>
import superTablePageFunction from '@/mixin/super-table-page-function';


export default {
  title: 'title_agent_company_manage',
  mixins: [superTablePageFunction],
  components: {},
  data() {
    return {

      dialogTitle: '',
      dialogFormVisible: false,
      formValue: {
        "isTest": 'N'
      },

      rules: {
        companyName: [
          { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
          { min: 3, max: 32, message: this.$tt('tip_length_in_min_max', { min: 3, max: 32 }), trigger: 'blur' }
        ],
        companyShortCode: [
          { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
          { min: 3, max: 16, message: this.$tt('tip_length_in_min_max', { min: 3, max: 32 }), trigger: 'blur' }
        ]
      },

      option: {
        //搜索框内容
        search: {
          //搜索框内容，key为搜索字段，label为标签提示
          model: [
            { label: "label_keyword", key: "keyword", type: 'input', }
          ],
        },
        action: [
          {
            label: ['label_new', 'label_agent_company'], attrs: { icon: "el-icon-plus" }, click: () => {
              this.dialogTitle = this.$tt(['label_new', 'label_agent_company'])
              this.dialogFormVisible = true
              this.formValue = {
                "isTest": 'N'
              }
            }
          },
        ],

        table: {
          url: "/ums-api/user/UserCompanyRpc/select.json?companyType=AGENT",
          attrs: {},
          model: [
            {
              key: 'companyName', label: 'label_company_name', align: 'left', width: 200, attrs: {
                formatter: (r, c, v, i) => {
                  return this.$formatNameCode(v, r.companyCode) + (r.isTest == 'Y' ? ' (TEST)' : '')

                }
              }
            },
            { key: 'companyCreditCode', label: 'label_unified_credit_code', align: 'left', width: 200 },
            {
              key: 'registAddress', label: 'label_register_address', align: 'left', width: 280, attrs: {
                formatter: (r, c, v, i) => {
                  if (v && v.length == 3) {
                    return v[1].replace(/\//g, '') + v[2]
                  }
                  return ''
                }
              }
            },
            {
              key: 'mailAddress', label: 'label_mail_address', align: 'left', width: 280, attrs: {
                formatter: (r, c, v, i) => {
                  if (v && v.length == 3) {
                    return v[1].replace(/\//g, '') + v[2]
                  }
                  return ''
                }
              }
            },
            { key: 'companyTel', label: 'label_company_landline', align: 'left', },
            { key: 'email', label: 'label_mailbox', align: 'left', },
            {
              key: 'contactName', label: 'label_contact', align: 'left', attrs: {
                formatter: (r, c, v, i) => {
                  let tmp = ''
                  if (r.contactName) {
                    tmp += r.contactName
                  }
                  if (r.contactPhone) {
                    tmp += '  ' + r.contactPhone
                  }
                  return tmp
                }
              }
            },
            {
              type: 'operate', width: 160, operate: [
                {
                  label: 'label_edit', click: (row) => {
                    this.dialogTitle = this.$tt(['label_edit', 'label_agent_company'])
                    this.formValue = JSON.parse(JSON.stringify(row))
                    this.dialogFormVisible = true
                  }
                },
                {
                  label: 'label_delete',
                  type: "confirm-button",
                  url: '/ums-api/user/UserCompanyRpc/remove.json',
                  message: 'label_fms_bank_card_confirm_delete',
                  buttonClass: "button_text_danger",
                  confirmButtonType: 'danger',
                  params: (row) => {
                    return { "id": row["id"] }
                  },
                  done: ['reload', 'tip']
                },
              ],
            }
          ]

        }
      }

    };
  },
  methods: {
    submitForm() {
      let _this = this

      _this.$refs['formEl'].validate((valid) => {
        if (valid) {

          _this.$ajax({
            url: '/ums-api/user/UserCompanyRpc/saveUpdateAgent.json',
            type: 'json',
            data: _this.formValue,
            success: (responseData) => {
              this.$message({
                showClose: true,
                message: this.$tt('tip_submit_success'),
                type: 'success'
              })
              _this.$refs['superTablePage'].reload()
              _this.dialogFormVisible = false
            }
          });

        } else {
          return false;
        }
      });


    }
  }
};

</script>
<style></style>
